package com.stek.admin;

import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

public class DummyActivity extends Activity {
	// ==================================================================
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestAddDevice();
		finish();
	}

	// ==================================================================
	private void requestAddDevice() {
		DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
		ComponentName compName = new ComponentName(getApplicationContext(),
				DeviceReceiver.class);
		if (devicePolicyManager.isAdminActive(compName)) {
			try {
				if (devicePolicyManager.isActivePasswordSufficient()) {
					devicePolicyManager.lockNow();
				}
			} catch (Exception e) {
				devicePolicyManager.lockNow();
			}

			return;
		}
		Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
		intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, compName);
		startActivity(intent);
	}
	// ==================================================================
}
